package com.the4man.cnbdw.action;

import com.opensymphony.xwork2.ModelDriven;
import com.the4man.cnbdw.service.EmployeeLocaltionHistoryService;
import com.the4man.cnbdw.service.EmployeeService;
import com.the4man.cnbdw.utils.Page;
import com.the4man.framework.action.BaseAction;
import com.the4man.framework.model.DataGrid;
import com.the4man.framework.model.EmployeeLocaltionHistory;
import com.the4man.framework.model.EmployeeLocaltionHistoryExample;
import com.the4man.framework.model.WarnInfo;
import com.the4man.framework.model.gen.LocaltionInfoExampleBase;
import com.the4man.framework.util.LOG;
import com.the4man.framework.util.PageJson;
import org.apache.commons.lang.StringUtils;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

@Action(
        value = "employeeLocaltionHistoryAction",
        results = {@Result(
                name = "listPage",
                location = "/cnbdw/employeeLocaltionHistory/list.jsp"
        )}
)
public class EmployeeLocaltionHistoryAction extends BaseAction implements ModelDriven<WarnInfo> {
    @Autowired
    private EmployeeService employeeService;
    @Autowired
    private EmployeeLocaltionHistoryService employeeLocaltionHistoryService;

    public EmployeeLocaltionHistoryAction() {
    }

    public String indexPage() {
        return "listPage";
    }

    public void getAllDatasourceList() {
        try {
            EmployeeLocaltionHistoryExample employeeLocaltionHistoryExample = new EmployeeLocaltionHistoryExample();
            LocaltionInfoExampleBase.Criteria cc = employeeLocaltionHistoryExample.createCriteria();
            if(StringUtils.isNotEmpty(this.getRequest().getParameter("empName"))) {
                cc.andEmpNameEqualTo(this.getRequest().getParameter("empName"));
            }

            if(StringUtils.isNotEmpty(this.getRequest().getParameter("start"))) {
                cc.andCreateTimeGreaterThanOrEqualTo(this.getRequest().getParameter("start"));
            }

            if(StringUtils.isNotEmpty(this.getRequest().getParameter("end"))) {
                cc.andCreateTimeLessThanOrEqualTo(this.getRequest().getParameter("end"));
            }

            this.employeeLocaltionHistoryService.countByExample(employeeLocaltionHistoryExample);
            Page<EmployeeLocaltionHistory> page = new Page();
            this.setPageProperties(page);
            this.employeeLocaltionHistoryService.selectByExample(employeeLocaltionHistoryExample, page);
            DataGrid d = new DataGrid();
            d.setRows(page.getData());
            d.setTotal(Long.valueOf((long)page.getRowCount()));
            this.writeJson(d);
        } catch (Exception var6) {
            LOG.error("获取数据失败", var6, new String[0]);
        }

    }

    public void delete() {
        PageJson json = new PageJson();

        try {
            int i = this.employeeLocaltionHistoryService.deleteByPrimaryKey(this.getRequest().getParameter("ids"), WarnInfo.class);
            if(i > 0) {
                json.setReturnMsg("删除成功！");
                json.setReturnFlag(true);
            } else {
                json.setReturnMsg("删除失败！");
                json.setReturnFlag(false);
            }
        } catch (Exception var3) {
            LOG.error("批量删除失败！", var3, new String[0]);
            json.setReturnMsg("删除失败！");
            json.setReturnFlag(false);
        }

        this.writeJson(json);
    }

    public WarnInfo getModel() {
        return null;
    }
}
